package com.woniuxy.enjoylife.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.enjoylife.entity.Goods_comment;
import com.woniuxy.enjoylife.entity.dto.ReturnGoodsCommentReplyDto;
import com.woniuxy.enjoylife.entity.dto.SelectGoodsCommentDto;
import com.woniuxy.enjoylife.mapper.Goods_commentMapper;
import com.woniuxy.enjoylife.service.Goods_commentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.enjoylife.utils.PageResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author teamEnjoyLife75
 * @since 2021-01-23
 */
@Service
public class Goods_commentServiceImpl extends ServiceImpl<Goods_commentMapper, Goods_comment> implements Goods_commentService {
    @Resource
    private Goods_commentMapper goodsCommentMapper;

    @Override
    public boolean delete(Goods_comment goodsComment) {
//        if (goodsCommentMapper.selectSingle(goodsComment).getUid().equals(goodsComment.getUid())) {
//            goodsComment.setStatus(1);
//            return goodsCommentMapper.delete(goodsComment) == 1;
//        }
//        return false;
        goodsComment.setStatus(1);
        return goodsCommentMapper.delete(goodsComment) == 1;
    }

    @Override
    public List<ReturnGoodsCommentReplyDto> selectGoodsCommentsDto(Goods_comment goodsComment) {
        List<ReturnGoodsCommentReplyDto> returnGoodsCommentReplyDtoList = goodsCommentMapper.selectGoodsCommentsDto(goodsComment.getGid());
        for (ReturnGoodsCommentReplyDto replyDto : returnGoodsCommentReplyDtoList) {
            if (replyDto.getUid().equals(goodsComment.getUid())) replyDto.setMine(true);
        }
        return returnGoodsCommentReplyDtoList;
    }

    @Override
    public PageResult<ReturnGoodsCommentReplyDto> selectGoodsComments(SelectGoodsCommentDto dto) {
        if (dto.getContent() != null && !dto.getContent().equals("")) {
            dto.setContent("%" + dto.getContent() + "%");
        }
        Page<ReturnGoodsCommentReplyDto> page = PageHelper.startPage(dto.getPage(), dto.getSize());
        List<ReturnGoodsCommentReplyDto> returnGoodsCommentReplyDtoList = goodsCommentMapper.SelectGoodsCommentDto2(dto);
        PageResult<ReturnGoodsCommentReplyDto> result = new PageResult<>();
        result.setCurrentPage(dto.getPage()).setPageSize(dto.getSize()).setTotalPage(page.getPageNum()).setTotal(page.getTotal()).setData(returnGoodsCommentReplyDtoList);
        return result;
    }


}
